<?php


namespace app\console\service\goods;

use app\dao\goods\GoodsDao;
use app\dao\goods\SupplierDao;
use app\dao\goods\TagDao;
use app\model\Goods;
use app\model\Supplier;
use app\model\Tag;

class GoodsService
{
    /**
     * @var
     */
    private Goods $goods;

    public function __construct(Goods $goods)
    {
        $this->goods = $goods ;
    }

    public function create($data)
    {
        $goodsDao = new GoodsDao();

        $pictures_url = array();
        $images_url = array();

        if (!empty($data['pictures']))
        {
            foreach ($data['pictures'] as $picture)
            {
                array_push($pictures_url, $picture->getPathName());
            }
        }

        if (!empty($data['images']))
        {
            foreach ($data['images'] as $images)
            {
                array_push($images_url, $images->getPathName());
            }
        }

        return $goodsDao->save([
            'supplier_id' => $data['supplier_id'],
            'name' => $data['name'],
            'number' => $data['number'],
            'type' => $data['type'],
            'tags' => json_encode($data['tags']),
            'is_packaged' => $data['is_packaged'],
            'material' => $data['material'],
            'suitable_people' => $data['suitable_people'],
            'has_storage' => $data['has_storage'],
            'customizable' => $data['customizable'],
            'model' => json_encode($data['model']),
            'other_features' => json_encode($data['other_features']),
            'finish_meterial' => $data['finish_meterial'],
            'style' => $data['style'],
            'dispatch_place_province' => $data['dispatch_place_province'],
            'dispatch_place_city' => $data['dispatch_place_city'],
            'dispatch_place_district' => $data['dispatch_place_district'],
            'dispatch_place_address' => $data['dispatch_place_address'],
            'skus' => json_encode($data['skus']),
            'machining_scheme_id' => $data['machining_scheme_id'],
            'attrs' => json_encode($data['attrs']),
            'invoice' => $data['invoice'],
            'guarantee' => $data['guarantee'],
            'return_promise' => $data['return_promise'],
            'brand' => $data['brand'],
            'detail' => $data['detail'],
            'fill' => $data['fill'],
            'remark' => $data['remark'],
            'pictures' => json_encode($pictures_url),
            'images' => json_encode($images_url),
            'status' => 0,
        ]);

    }


}


